package com.itheima.dao.controller;


import com.itheima.dao.domain.User;
import com.itheima.dao.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller()
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/user-save")
    public String save(){
        userService.save();
        return "save.jsp";
    }
    @RequestMapping("/user-save2")
    public ModelAndView save2(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("username","itheima");
        modelAndView.setViewName("save.jsp");
        return modelAndView;
    }

    @RequestMapping("user-save3")
    @ResponseBody
    public User save3(){
        User user= new User();
        user.setAge(1);
        user.setName("username");
        return user;
    }
}
